const app = getApp()

Page({
  data: {
    barMarginTop: '16',
    barHeight: '52',
    barWidth: '0',
    scrollHeight: '',
    cardCollectionData: {},
    // mainBg: 'http://qq3fpcend.hn-bkt.clouddn.com/indexBg.jpg',
    // btnBg: 'https://moonlight-1305115047.cos.ap-guangzhou.myqcloud.com/cardCollection/btnBg.png',
    drawingCardVisible: false,
    drawingImgSrc: '', // 抽卡的卡片路径
    drawingImgName: '', // 抽卡的卡片名称
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBarHeight()
    this.setListHeight()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData()
  },

  /**
   * 设置导航栏高度
   */
  getBarHeight() {
    let systemInfo = wx.getSystemInfoSync()
    let	statusBarHeight = systemInfo.statusBarHeight
    let menu = wx.getMenuButtonBoundingClientRect()

    let	barMarginTop = menu.top
    let	barHeight = menu.height + 10
    let barWidth = systemInfo.windowWidth - (systemInfo.windowWidth - menu.right + menu.width)

    this.setData({
      barMarginTop: barMarginTop,
      barHeight: barHeight,
      barWidth: barWidth
    })
  },

  /**
   * 设置scroll-view高度
   */
  setListHeight() {
    let systemInfo = wx.getSystemInfoSync(),
      rpx = systemInfo.windowWidth / 750, // 计算rpx
      hei = parseInt(this.data.barMarginTop) + parseInt(this.data.barHeight) + 4,
      tapHeight = Math.floor(rpx * hei * 2), // tap高度
      scrollHeight = systemInfo.windowHeight - tapHeight; // swiper高度
    this.setData({
      scrollHeight
    });
  },

  getData() {
    let data = app.getCardCollectionData()
    this.setData({
      cardCollectionData: data
    })
  },
  handleDrawing(e) {
    let type = e.currentTarget.dataset.type
    if (type === "0") {
      // 免费抽卡
      this.drawingCard()
    } else if (type === "1") {
      // 付费抽卡
    } else if (type === "2") {
      // 已开奖, 查看中奖详情
    }
  },
  drawingCard() {
    let currentCard = app.drawingCard()
    this.setData({
      drawingImgSrc: currentCard.bigCardUrl,
      drawingImgName: currentCard.name,
      drawingCardVisible: true
    })
    app.refreshCardsList(currentCard.id)
  },
  hiddenDrawingCard () {
    this.setData({
      drawingCardVisible: false
    })
  },
  goIndex() {
    wx.navigateBack({
      fail: function() {
        wx.navigateTo({
          url: '/pages/index/index',
        })
      }
    })
  },
  goActivityRules() {
    // goActivityRules
  },
  goMyCards() {
    wx.navigateTo({
      url: '/cardCollectionPack/pages/cardCollection/cardsDisplay/index',
    })
  },
})
